@extends('admin.common.base-master')

@section('html-head')
    <style type="text/css">
        .divcss5_list_title{background:#eeeeee; border:1px solid #cccccc; padding:1em;}
        .divcss5_list_content{padding:1em;}
        #tinybox{position:absolute; display:none; padding:10px; background:url('{{url('images/preload.gif')}}') no-repeat 50% 50%;  z-index:2000;}
        #tinymask{position:absolute; display:none; top:0; left:0; height:100%; width:100%; background:#000000; z-index:1500;}
        #tinycontent{background:#ffffff; font-size:1.1em;}

        #n{margin:10px auto; width:920px; border:1px solid #CCC;font-size:12px; line-height:30px;}
        #n a{ padding:0 4px; color:#333}
        .sx{padding: 10px}
        .sx-btn{width: 64px;height: 30px;background-color: #4dbcd3;color: #fff;border: #4dbcd3;border-radius: 7%;}
    </style>
    <link href="{{url('css/admin/pagenum.css')}}" rel="stylesheet" />
@endsection

@section('html-body')
    <div id="content">
        <!-- cur-position start -->
        <div id="cur-position">
            <span class="tit">当前位置：</span>
            <a href="#">论坛列表</a>
        </div>

        <div class="filter-box clearfix">
            <div class="fr" style="margin-top: 10px;">
                <a class="addBtn" href="{{route('Admin.Home.forumSet')}}">新增</a>
            </div>
        </div>
        <div class="table-box">
            <table class="table">
                <thead>
                <tr>
                    <th>展示图</th>
                    <th>ID</th>
                    <th>标题</th>
                    <th>描述</th>
                    <th>阅读数</th>
                    <th>评论数</th>
                    <th>发布时间</th>
                    <th>是否精选</th>
                    <th>操作</th>
                </tr>
                </thead>
                <tbody>
                @if(count($forums) > 0)
                    @foreach($forums as $forum)
                        <tr id="plan_{{$forum->id}}">
                            <td class="account-td" style="width: 5%;">
                                <span class="photo" style="border-radius: 100%;display:initial">
                                    <img src="@if($forum){{$forum->img_url}} @endif" alt="">
                                </span>
                            </td>
                            <td>{{$forum->id}}</td>
                            <td>{{$forum->title}}</td>
                            <td>{{$forum->desc}}</td>
                            <td>{{$forum->read_num}}</td>
                            <td>{{$forum->discuss_count}}<a href="{{route('Admin.Home.forumDiscussList')}}?id={{$forum->id}}">(查看)</a></td>
                            <td>{{$forum->created_at}}</td>
                            <td>@if($forum->is_essence == 0)<span class="color2">否</span> @else <span class="color4">是</span> @endif</td>
                            <td><a class="color2" href="@if($forum){{route('Admin.Home.forumSet')}}?id={{$forum->id}} @endif">编辑</a> <span>|</span> <a href="javascript:void(0);" class="del" data-id="{{$forum->id}}">删除 </a></td>
                        </tr>
                    @endforeach
                @endif
                </tbody>
                <tfoot class="order-gl">

                </tfoot>
            </table>
        </div>
    </div>

    <script>

        $(function(){

            $(document).on("click",".del",function(){
                var id = $(this).attr("data-id");

                noty({
                    text: '可能影响用户的讨论，你确定要删除吗?',
                    buttons: [
                        {addClass: 'btn btn-primary', text: '确定', onClick: function($noty) {
                                $noty.close();
                                $.ajax({
                                    url:'{{route('Api.Admin.Forum.delForum')}}',
                                    type:'post',
                                    dataType:'json',
                                    data:{id:id},
                                    success:function(obj){
                                        if(obj.level == "success"){
                                            $("#plan_"+id).hide('slow');
                                        }else{
                                            noty({type:obj.level,text:obj.message,timeout:600});
                                        }
                                    },
                                    error:function(obj){
                                        console.log(obj);
                                    }

                                });
                            }
                        },
                        {addClass: 'btn btn-danger', text: '取消', onClick: function($noty) {
                                $noty.close();
                            }
                        }
                    ]
                });
            });
        });
    </script>
@endsection